<template>
  <div class="sidebar" :class="{ 'sidebar-show': isShow }">
    <!-- 快捷功能区 -->
    <div class="quick-actions">
      <div class="action-item" @click="scrollToTop">
        <span class="icon">⬆️</span>
        <span class="text">返回顶部</span>
      </div>
      <div class="action-item" @click="goToCart">
        <span class="icon">🛒</span>
        <span class="text">购物车</span>
        <span v-if="cartCount > 0" class="badge">{{ cartCount }}</span>
      </div>
      <div class="action-item" @click="goToFavorites">
        <span class="icon">❤️</span>
        <span class="text">收藏夹</span>
      </div>
      <div class="action-item" @click="showHistory">
        <span class="icon">🕒</span>
        <span class="text">浏览历史</span>
      </div>
    </div>

    <!-- 客服区域 -->
    <div class="user-service">
      <div class="action-item" @click="contactService">
        <span class="icon">💬</span>
        <span class="text">在线客服</span>
      </div>
      <div class="action-item" @click="showFeedback">
        <span class="icon">📝</span>
        <span class="text">意见反馈</span>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()
const isShow = ref(true)
const cartCount = ref(0) // 后续从状态管理获取

// 返回顶部
const scrollToTop = () => {
  window.scrollTo({
    top: 0,
    behavior: 'smooth'
  })
}

// 跳转到购物车
const goToCart = () => {
  router.push('/cart')
}

// 跳转到收藏夹
const goToFavorites = () => {
  router.push('/favorites')
}

// 显示浏览历史
const showHistory = () => {
  // TODO: 实现浏览历史展示逻辑
  console.log('显示浏览历史')
}

// 联系客服
const contactService = () => {
  // TODO: 实现客服对话功能
  console.log('联系客服')
}

// 显示反馈
const showFeedback = () => {
  // TODO: 实现反馈功能
  console.log('显示反馈')
}
</script>

<style scoped>
.sidebar {
  position: fixed;
  right: 20px;
  bottom: 100px;
  z-index: 999;
  background-color: var(--bg-color);
  border-radius: 4px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

.action-item {
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  position: relative;
  transition: all 0.3s;
}

.action-item:hover {
  background-color: var(--bg-color-overlay);
}

.action-item .icon {
  font-size: 20px;
  margin-bottom: 4px;
}

.action-item .text {
  font-size: 12px;
  color: var(--text-regular);
  display: none;
}

.action-item:hover .text {
  display: block;
}

.badge {
  position: absolute;
  top: 0;
  right: 0;
  background-color: var(--danger-color);
  color: white;
  font-size: 12px;
  padding: 2px 6px;
  border-radius: 10px;
  transform: translate(50%, -50%);
}

.quick-actions {
  border-bottom: 1px solid var(--border-light);
}

.user-service {
  margin-top: 10px;
}

/* 响应式设计 */
@media screen and (max-width: 768px) {
  .sidebar {
    bottom: 0;
    right: 0;
    left: 0;
    display: flex;
    justify-content: space-around;
    background-color: var(--bg-color);
    border-top: 1px solid var(--border-color);
  }

  .quick-actions, .user-service {
    display: flex;
  }

  .action-item {
    padding: 8px 15px;
  }

  .action-item .text {
    display: block;
  }
}
</style>